package com.goolecloud.springcloud.controller;

import com.goolecloud.springcloud.entities.Dept;
import com.goolecloud.springcloud.service.DeptService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class DeptController {
    @Autowired
    DeptService service;
    @RequestMapping(value = "/dept/add",method = RequestMethod.POST)
    public boolean add(Dept dept){
        return service.add(dept);
    }

    @RequestMapping(value = "/dept/get/{id}",method = RequestMethod.GET)
    @HystrixCommand(fallbackMethod ="defaultFallbackDet" )
    public Dept get(@PathVariable("id") Long id){
        return service.get(id);
    }

    @RequestMapping(value = "/dept/list",method = RequestMethod.GET)
    public List<Dept> list(){
        return service.list();
    }

    public Dept defaultFallbackDet(@PathVariable("id") Long id){
        System.out.println("dfjhsjfhjksdh");
        Dept dept=new Dept();
        dept.setDeptno(id);
        dept.setDname("该id没有对应的信息");
        dept.setDb_source("No id database in mysql");
        return dept;
    }
}
